function curry(fn){
    function curryFn(...args){
        if(args.length === fn.length){
            return fn(...args)
        } else {
            return (...params) => {
                return curryFn(...[...args, ...params])
            }
        }
    }
    return curryFn
}
const a = (a, b, c, d) => a + b + c + d
const fn = curry(a)
console.log(fn(1, 2)(2, 4))

function currySum(...args){
    let arr = [...args]
    function curryFn(...params){
        arr = arr.concat(params)
        return curryFn
    }
    curryFn.toString = () => {
        return arr.reduce((p, c) => p + c, 0)
    }
    return curryFn

}
console.log(currySum(1, 2, 3, 4)(5)(6, 7).toString())